﻿using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QuanLyDiem.Controllers
{
    public class C_Khoa
    {
        public static void LoadDataSource(LookUpEdit lookUpedit, Context db = null)
        {
            if (db == null) db = new Context();
            lookUpedit.Properties.Columns.Clear();
            lookUpedit.Properties.DataSource = db.Khoas.OrderBy(a => a.Ten_khoa).ToList();
            lookUpedit.Properties.Columns.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo("Ten_khoa", "Tên khoa"));
            lookUpedit.Properties.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFit;
            lookUpedit.Properties.DisplayMember = "Ten_khoa";
            lookUpedit.Properties.ValueMember = "ID_khoa";
            lookUpedit.Properties.NullText = "";
            lookUpedit.ToolTip = lookUpedit.Properties.NullValuePrompt = "Chọn khoa";

            lookUpedit.Properties.NullValuePromptShowForEmptyValue = true;
            lookUpedit.Properties.AllowDropDownWhenReadOnly = DevExpress.Utils.DefaultBoolean.True;
            lookUpedit.ItemIndex = 0;
        }
        public static void LoadDataSource(RepositoryItemLookUpEdit lookUpedit, Context db = null)
        {
            if (db == null) db = new Context();
            lookUpedit.Columns.Clear();
            lookUpedit.DataSource = db.Khoas.OrderBy(a => a.Ten_khoa).ToList();
            lookUpedit.Columns.Add(new DevExpress.XtraEditors.Controls.LookUpColumnInfo("Ten_khoa", "Tên khoa"));
            lookUpedit.DisplayMember = "Ten_khoa";
            lookUpedit.ValueMember = "ID_khoa";
            lookUpedit.NullText = string.Empty;
            lookUpedit.NullValuePrompt = string.Empty;
            lookUpedit.NullValuePromptShowForEmptyValue = true;
            lookUpedit.AllowDropDownWhenReadOnly = DevExpress.Utils.DefaultBoolean.False;
        }
 
    }
}
